<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <el-form-item label="名称" prop="name">
        <el-input v-model="dataForm.name" placeholder="名称"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-input v-model="dataForm.sex" placeholder="性别"></el-input>
      </el-form-item>
      <el-form-item label="党组织职务" prop="partyDuty">
        <el-input
          v-model="dataForm.partyDuty"
          placeholder="党组织职务"
        ></el-input>
      </el-form-item>
       <el-form-item label="党组织职务数量" prop="partyDutyCount">
        <el-input
          v-model="dataForm.partyDutyCount"
          placeholder="党组织职务数量"
        ></el-input>
      </el-form-item>
      <el-form-item label="村(居)委会职务" prop="villageDuty">
        <el-input
          v-model="dataForm.villageDuty"
          placeholder="村(居)委会职务"
        ></el-input>
      </el-form-item>
       <el-form-item label="村(居)委会职务数量" prop="villageDutyCount">
        <el-input
          v-model="dataForm.villageDutyCount"
          placeholder="村(居)委会职务数量"
        ></el-input>
      </el-form-item>
      <el-form-item label="现职时间" prop="presentTimet">
        <el-input
          v-model="dataForm.presentTime"
          placeholder="现职时间"
        ></el-input>
      </el-form-item>

      <!-- <el-form-item label="研判人员" prop="judge">
        <el-input v-model="dataForm.judge" placeholder="研判人员"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="手机号" prop="phone">
        <el-input v-model="dataForm.phone" placeholder="手机号"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="备注" prop="remark">
        <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item> -->
      <el-form-item label="社区主键" prop="communityId">
        <el-input
          v-model="dataForm.communityId"
          placeholder="社区主键"
        ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
// import { fileUpload } from '@/utils';
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        name: "",
        sex: "",
        partyDuty: "",
        villageDuty: "",
        presentTime: "",
        judge: "",
        phone: "",
        remark: "",
        communityId: ""
      },
      dataRule: {
        name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
        sex: [{ required: true, message: "性别不能为空", trigger: "blur" }],
        partyDuty: [
          { required: true, message: "党组织职务不能为空", trigger: "blur" }
        ],
        partyDutyCount: [
          { required: true, message: "党组织职务数量不能为空", trigger: "blur" }
        ],
        villageDuty: [
          { required: true, message: "村(居)委会职务不能为空", trigger: "blur" }
        ],
        villageDutyCount: [
          { required: true, message: "村(居)委会职务数量不能为空", trigger: "blur" }
        ],
        presentTime: [
          { required: true, message: "现职时间不能为空", trigger: "blur" }
        ],
        judge: [{ required: true, message: "研判人员不能为空", trigger: "blur" }],
        phone: [{ required: true, message: "手机号不能为空", trigger: "blur" }],
        remark: [
          { required: true, message: "备注不能为空", trigger: "blur" }
        ],
        communityId: [
          { required: true, message: "社区主键不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    // customUpload(imageUrl){
    //     fileUpload(imageUrl).then(response => {
    //        this.dataForm.imageUrl.push(response.data.url) ;
    //       })
    // },
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl("/shequ/twoCommittee/delete"),
            method: "post",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.name = data.trees.name;
              this.dataForm.sex = data.trees.sex;
              this.dataForm.partyDuty = data.trees.partyDuty;
              this.dataForm.partyDutyCount = data.trees.partyDutyCount;
              this.dataForm.villageDuty = data.trees.villageDuty;
              this.dataForm.villageDutyCount= data.trees.villageDutyCount;
              this.dataForm.presentTime = data.trees.presentTime;

              // this.dataForm.judge = data.trees.judge;
              // this.dataForm.phone = data.trees.phone;
              // this.dataForm.remark = data.trees.remark;
              this.dataForm.communityId = data.trees.communityId;
            }
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              `/shequ/twoCommittee/${!this.dataForm.id ? "save" : "update"}`
            ),
            method: "post",
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              name: this.dataForm.name,
              sex: this.dataForm.sex,
              partyDuty: this.dataForm.partyDuty,
              partyDutyCount: this.dataForm.partyDutyCount,
              villageDuty: this.dataForm.villageDuty,
              villageDutyCount: this.dataForm.villageDutyCount,
              presentTime: this.dataForm.presentTime,
              // judge: this.dataForm.judge,
              // phone: this.dataForm.phone,
              // remark: this.dataForm.remark,
              communityId: this.dataForm.communityId
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",

                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
